home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / src / ov-str-mat.cc < prev    next >
C/C++ Source or Header  |  1997-03-07  |  5KB  |  230 lines

  1. /*
  2.  
  3. Copyright (C) 1996 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. #if defined (__GNUG__)
  24. #pragma implementation
  25. #endif
  26.  
  27. #ifdef HAVE_CONFIG_H
  28. #include <config.h>
  29. #endif
  30.  
  31. #include "lo-ieee.h"
  32. #include "mx-base.h"
  33.  
  34. #include "oct-obj.h"
  35. #include "ops.h"
  36. #include "ov-re-mat.h"
  37. #include "ov-str-mat.h"
  38. #include "gripes.h"
  39. #include "pr-output.h"
  40.  
  41. int
  42. octave_char_matrix_str::t_id (-1);
  43.  
  44. const string
  45. octave_char_matrix_str::t_name ("string");
  46.  
  47. static octave_value *
  48. default_numeric_conversion_function (const octave_value& a)
  49. {
  50.   CAST_CONV_ARG (const octave_char_matrix_str&);
  51.  
  52.   return new octave_matrix (v.matrix_value ());
  53. }
  54.  
  55. type_conv_fcn
  56. octave_char_matrix_str::numeric_conversion_function (void) const
  57. {
  58.   return default_numeric_conversion_function;
  59. }
  60.  
  61. octave_value
  62. octave_char_matrix_str::index (const octave_value_list& idx) const
  63. {
  64.   octave_value retval;
  65.  
  66.   int len = idx.length ();
  67.  
  68.   switch (len)
  69.     {
  70.     case 2:
  71.       {
  72.     idx_vector i = idx (0).index_vector ();
  73.     idx_vector j = idx (1).index_vector ();
  74.  
  75.     retval = octave_value (charMatrix (matrix.index (i, j)), true);
  76.       }
  77.       break;
  78.  
  79.     case 1:
  80.       {
  81.     idx_vector i = idx (0).index_vector ();
  82.  
  83.     retval = octave_value (charMatrix (matrix.index (i)), true);
  84.       }
  85.       break;
  86.  
  87.     default:
  88.       error ("invalid number of indices (%d) for matrix value", len);
  89.       break;
  90.     }
  91.  
  92.   return retval;
  93. }
  94.  
  95. extern void assign (Array2<char>&, const Array2<char>&);
  96.  
  97. void
  98. octave_char_matrix_str::assign (const octave_value_list& idx,
  99.                 const charMatrix& rhs)
  100. {
  101.   int len = idx.length ();
  102.  
  103.   // XXX FIXME XXX
  104.   charMatrix tmp = rhs;
  105.   if (tmp.rows () == 1 && tmp.columns () == 0)
  106.     tmp.resize (0, 0);    
  107.  
  108.   switch (len)
  109.     {
  110.     case 2:
  111.       {
  112.     idx_vector i = idx (0).index_vector ();
  113.     idx_vector j = idx (1).index_vector ();
  114.  
  115.     matrix.set_index (i);
  116.     matrix.set_index (j);
  117.  
  118.     ::assign (matrix, tmp);
  119.       }
  120.       break;
  121.  
  122.     case 1:
  123.       {
  124.     idx_vector i = idx (0).index_vector ();
  125.  
  126.     matrix.set_index (i);
  127.  
  128.     ::assign (matrix, tmp);
  129.       }
  130.       break;
  131.  
  132.     default:
  133.       error ("invalid number of indices (%d) for indexed matrix assignment",
  134.          len);
  135.       break;
  136.     }
  137. }
  138.  
  139. octave_value
  140. octave_char_matrix_str::all (void) const
  141. {
  142.   octave_value retval;
  143.   error ("octave_char_matrix_str::all(): not implemented");
  144.   return retval;
  145. }
  146.  
  147. octave_value
  148. octave_char_matrix_str::any (void) const
  149. {
  150.   octave_value retval;
  151.   error ("octave_char_matrix_str::any(): not implemented");
  152.   return retval;
  153. }
  154.  
  155. bool
  156. octave_char_matrix_str::valid_as_scalar_index (void) const
  157. {
  158.   bool retval = false;
  159.   error ("octave_char_matrix_str::valid_as_scalar_index(): not implemented");
  160.   return retval;
  161. }
  162. bool
  163. octave_char_matrix_str::valid_as_zero_index (void) const
  164. {
  165.   bool retval = false;
  166.   error ("octave_char_matrix_str::valid_as_zero_index(): not implemented");
  167.   return retval;
  168. }
  169.  
  170. bool
  171. octave_char_matrix_str::is_true (void) const
  172. {
  173.   bool retval = false;
  174.   error ("octave_char_matrix_str::is_true(): not implemented");
  175.   return retval;
  176. }
  177.  
  178. Matrix
  179. octave_char_matrix_str::matrix_value (bool force_string_conv) const
  180. {
  181.   Matrix retval;
  182.  
  183.   int flag = force_string_conv;
  184.  
  185.   if (! flag)
  186.     flag = Vimplicit_str_to_num_ok;
  187.  
  188.   if (flag < 0)
  189.     gripe_implicit_conversion ("string", "real matrix");
  190.  
  191.   if (flag)
  192.     retval = Matrix (matrix);
  193.   else
  194.     gripe_invalid_conversion ("string", "real matrix");
  195.  
  196.   return retval;
  197. }
  198.  
  199. string_vector
  200. octave_char_matrix_str::all_strings (void) const
  201. {
  202.   int n = matrix.rows ();
  203.  
  204.   string_vector retval (n);
  205.  
  206.   for (int i = 0; i < n; i++)
  207.     retval[i] = matrix.row_as_string (i, true);
  208.  
  209.   return retval;
  210. }
  211.  
  212. string
  213. octave_char_matrix_str::string_value (void) const
  214. {
  215.   return matrix.row_as_string (0);  // XXX FIXME??? XXX
  216. }
  217.  
  218. void
  219. octave_char_matrix_str::print (ostream& os, bool pr_as_read_syntax)
  220. {
  221.   octave_print_internal (os, matrix, pr_as_read_syntax, true,
  222.              struct_indent);
  223. }
  224.  
  225. /*
  226. ;;; Local Variables: ***
  227. ;;; mode: C++ ***
  228. ;;; End: ***
  229. */
  230.